import { ErrorMessageMode } from '/#/axios';
import { defHttp } from '/@/utils/http';
import { mallHttp } from '/@/utils/http';
import type { WeChatUrlParams, GoodWeChatUrlParams } from './model/commonModel';

enum Api {
  WeChatUrl = '/tool/common/link-url',
  GoodWeChatUrl = '/wechat/common/good-urllink',
}

// 获取卡牌列表
export function WeChatUrlApi(params: WeChatUrlParams, model: ErrorMessageMode = 'none') {
  return defHttp.post<string>(
    {
      url: Api.WeChatUrl,
      data: params,
    },
    {
      errorMessageMode: model,
    }
  );
}

// 通用卡牌游戏获取微信商品短链
export function GoodWeChatUrlApi(params: GoodWeChatUrlParams, model: ErrorMessageMode = 'none') {
  const jsonParams = {
    type: params.type,
    good_id: JSON.stringify(params.good_id),
    game_id: params.game_id,
  };
  return mallHttp.post<{ url_link: string }>(
    {
      url: Api.GoodWeChatUrl,
      data: jsonParams,
    },
    {
      errorMessageMode: model,
    }
  );
}
